package utils

import "strings"

func CronExpGetWeekDayVal(s string, v *int) bool {
	switch strings.ToLower(s) {
	case "sun":
		*v = 1
		return true
	case "mon":
		*v = 2
		return true
	case "tue":
		*v = 3
		return true
	case "wed":
		*v = 4
		return true
	case "thu":
		*v = 5
		return true
	case "fri":
		*v = 6
		return true
	case "sat":
		*v = 7
		return true
	}
	return false
}

func CronExpGetMonthVal(s string, v *int) bool {
	switch strings.ToLower(s) {
	case "jan":
		*v = 1
		return true
	case "feb":
		*v = 2
		return true
	case "mar", "march":
		*v = 3
		return true
	case "apr", "april":
		*v = 4
		return true
	case "may":
		*v = 5
		return true
	case "jun", "june":
		*v = 6
		return true
	case "jul", "july":
		*v = 7
		return true
	case "aug", "august":
		*v = 8
		return true
	case "sep", "september":
		*v = 9
		return true
	case "oct", "october":
		*v = 10
		return true
	case "nov", "november":
		*v = 11
		return true
	case "dec", "december":
		*v = 12
		return true
	}
	return false
}

func CronExpGetIntVal(s string, v *int) bool {
	if len(s) == 0 {
		return false
	}
	if s[0] >= '0' && s[0] <= '9' {
		v0 := StrToIntDef(s, -1)
		if v0 == -1 {
			return false
		}
		*v = v0
		return true
	}
	return false
}
